package com.cisc.controller;

import com.cisc.business.user.dto.UserInfo;
import com.cisc.business.user.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: XXX
 * @author: daizh
 * @time: 2021/6/20 0:18
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/userId/{userId}")
    public UserInfo getUserById(@PathVariable("userId") Integer userId) {
        return userService.getUserById(userId);
    }

    @GetMapping("/userName/{username}")
    public List<UserInfo> getUserByName(@PathVariable("username")String username) {
        return userService.getUserByName(username);
    }

    @GetMapping("/allUsers")
    public List<UserInfo> getAllUsers() {
        return userService.getAllUsers();
    }

    @PostMapping("/save")
    public String saveUserInfo(@RequestBody UserInfo userInfo) {
        try {
            userService.saveUserInfo(userInfo);
            return "success";
        } catch (Exception e) {
            e.printStackTrace();
            return "fail";
        }
    }
}
